package com.wu;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

/***
 * @Author 徐庶   QQ:1092002729
 * @Slogan 致敬大师，致敬未来的你
 */
public class App {
  private static SqlSessionFactory sqlSessionFactory;
  static {
    try {

        String resource = "mybatis-config.xml";
        //将XML配置文件构建为Configuration配置类
        InputStream inputStream =   Resources.getResourceAsStream(resource);
        // 通过加载配置文件流构建一个SqlSessionFactory  DefaultSqlSessionFactory
        sqlSessionFactory = new  SqlSessionFactoryBuilder().build(inputStream);
      } catch (IOException e) {
        e.printStackTrace();
       }
       }
           //获取SqlSession连接
            public static SqlSession getSession() {
                // 数据源 执行器  DefaultSqlSession
                SqlSession sqlSession = sqlSessionFactory.openSession(true);
                return sqlSession;
             }
}





